//
//  UIView+OAExtension.m
//  OASDK_Works
//
//  Created by ChenJie on 2/29/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "UIView+OAExtension.h"
#import "UIColor+OAExtension.h"

NSString *const OAExtensionStringConstant = @"OAExtensionStringConstant";
const CGFloat OAExtensionCGFloatConstant = 12.34;
static NSString *const kOAExtensionStaticStringConstant = @"kOAExtensionStaticStringConstant";

@implementation UIView (OAExtension)

/*  */
- (void)oa_showBounds {
    self.backgroundColor = OARandomColor();
    
    for (UIView *subview in self.subviews) {
        [subview oa_showBounds];
    }
}

/*  */
- (void)oa_showBoundsWithAlpha:(CGFloat)alpha {
    self.backgroundColor = OARandomColor(alpha);
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = OARandomColor(alpha).CGColor;
    
    for (UIView *subview in self.subviews) {
        [subview oa_showBoundsWithAlpha:alpha];
    }
}

/*  */
- (UIView *)oa_firstResponder {
    if (self.isFirstResponder) {
        return self;
    }
    for (UIView *subView in self.subviews) {
        id responder = [subView oa_firstResponder];
        if (responder) {
            return responder;
        }
    }
    return nil;
}

/*  */
- (UIViewController *)oa_controller {
    UIResponder *responder = [self nextResponder];
    while (responder) {
        if ([responder isKindOfClass:UIViewController.class]) {
            return (UIViewController *)responder;
        }
        responder = [responder nextResponder];
    }
    return nil;
}

/* */
- (UIScrollView *)oa_scrollViewContainer {
    UIResponder *responder = [self nextResponder];
    while (responder) {
        if ([responder isKindOfClass:UIScrollView.class]) {
            return (UIScrollView *)responder;
        }
        responder = [responder nextResponder];
    }
    return nil;
}

- (void)oa_removeAllSubViews {
    for (UIView *subview in self.subviews) {
        [subview removeFromSuperview];
    }
}

@end
